#include "lcd_ll.h"

// 延时函数声明（需在其他文件中实现）
void delay_us(uint32_t us);

// 8×16字模数据
static const uint8_t zimo_8x16[][16] = { 
/*--  文字:  0  --*/
{0xF8,0x04,0x04,0x04,0xF8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  1  --*/
{0x00,0x08,0xFC,0x00,0x00,0x00,0x00,0x02,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  2  --*/
{0x18,0x84,0x44,0x24,0x18,0x00,0x03,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  3  --*/
{0x08,0x04,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  4  --*/
{0x40,0xB0,0x88,0xFC,0x80,0x00,0x00,0x00,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  5  --*/
{0x3C,0x24,0x24,0x24,0xC4,0x00,0x01,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  6  --*/
{0xF8,0x24,0x24,0x2C,0xC0,0x00,0x01,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  7  --*/
{0x0C,0x04,0xE4,0x1C,0x04,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  8  --*/
{0xD8,0x24,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  9  --*/
{0x38,0x44,0x44,0x44,0xF8,0x00,0x00,0x03,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  V  --*/
{0x04,0x7C,0x80,0xE0,0x1C,0x04,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  A  --*/
{0x00,0xE0,0x9C,0xF0,0x80,0x00,0x02,0x03,0x00,0x00,0x03,0x02,0x00,0x00,0x00,0x00},
/*--  文字:  m  --*/
{0xE0,0x20,0xE0,0x20,0xC0,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  :  --*/
{0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  .  --*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  -  --*/
{0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
/*--  文字:  S  --*/
{0x18,0x24,0x24,0x44,0x8C,0x00,0x03,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00},
};

// 16×16汉字字模数据
static const uint8_t zimo_12x16[][24] = {
    // 本
    {0x04,0x04,0x84,0x64,0x14,0xFF,0x14,0x64,0x84,0x04,0x04,0x00,
     0x02,0x01,0x02,0x02,0x02,0x0F,0x02,0x02,0x02,0x01,0x02,0x00},
    // 安
    {0x2C,0x24,0xA4,0x64,0x3D,0x26,0x24,0x24,0xE4,0x24,0x2C,0x00,
     0x08,0x08,0x09,0x05,0x05,0x02,0x02,0x05,0x04,0x08,0x00,0x00},
    // 输
    {0x34,0x2C,0xF7,0xA4,0xE8,0xA4,0xEA,0x09,0xCA,0x04,0xE8,0x00,
     0x01,0x01,0x0F,0x00,0x0F,0x02,0x0F,0x00,0x03,0x08,0x0F,0x00},
    // 出
    {0x80,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x1E,0x80,0x00,
     0x07,0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0x0F,0x00},
    // 电
    {0xFC,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0xFC,0x00,0x00,0x00,
     0x03,0x01,0x01,0x01,0x07,0x09,0x09,0x09,0x09,0x08,0x0E,0x00},
    // 压
    {0x00,0xFE,0x02,0x42,0x42,0x42,0xFA,0x42,0x42,0x42,0x02,0x00,
     0x08,0x07,0x08,0x08,0x08,0x08,0x0F,0x08,0x09,0x0A,0x08,0x00},
    // 流
    {0x22,0x44,0x00,0x24,0xB4,0x2C,0xA5,0x26,0xA4,0x34,0x64,0x00,
     0x04,0x02,0x08,0x04,0x03,0x00,0x0F,0x00,0x07,0x08,0x0E,0x00},
    // 放
    {0x08,0xF9,0x4A,0x48,0xC8,0x20,0x10,0xEF,0x08,0xF8,0x08,0x00,
     0x08,0x07,0x00,0x08,0x0F,0x00,0x08,0x05,0x02,0x05,0x08,0x00},
    // 池
    {0x22,0x44,0x40,0xFC,0x20,0x10,0xFF,0x08,0x04,0xFC,0x00,0x00,
     0x04,0x02,0x00,0x07,0x08,0x08,0x0B,0x08,0x09,0x09,0x0C,0x00},
    // 容
    {0x46,0x42,0xAA,0xA6,0x92,0x8B,0x92,0xA6,0xAA,0x42,0x46,0x00,
     0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00},
    // 量
    {0x08,0xFF,0xA9,0xA9,0xA9,0xFB,0xAD,0xA9,0xA9,0xFF,0x08,0x00,
     0x08,0x0A,0x0A,0x0A,0x0A,0x0F,0x0A,0x0A,0x0A,0x0A,0x08,0x00},
    // 周
    {0x00,0x00,0xFF,0x21,0xA9,0xA9,0xBD,0xA9,0xA9,0x21,0xFF,0x00,
     0x08,0x04,0x03,0x00,0x03,0x02,0x02,0x02,0x0B,0x08,0x0F,0x00},
    // 期
    {0x04,0xFF,0x54,0x54,0xFF,0x04,0x00,0xFE,0x92,0x92,0xFE,0x00,
     0x09,0x05,0x01,0x01,0x05,0x09,0x08,0x07,0x00,0x08,0x0F,0x00},
    // 版
    {0x00,0xFE,0x90,0x9F,0x10,0xFE,0x12,0xF2,0x12,0x91,0x71,0x00,
     0x08,0x07,0x00,0x0F,0x04,0x03,0x08,0x05,0x02,0x05,0x08,0x00},
    // 通
    {0x11,0xF2,0x00,0xF9,0xA9,0xAB,0xFD,0xAD,0xAB,0xF8,0x00,0x00,
     0x08,0x07,0x08,0x0B,0x08,0x08,0x0B,0x08,0x0A,0x0B,0x08,0x00},
    // 信
    {0x10,0xFC,0x03,0x04,0x54,0x54,0x55,0x56,0x54,0x54,0x04,0x00,
     0x00,0x0F,0x00,0x00,0x0F,0x05,0x05,0x05,0x05,0x0F,0x00,0x00},
    // 断
    {0xFC,0x92,0x54,0xFF,0x54,0x92,0x00,0xFE,0x12,0xF2,0x11,0x00,
     0x07,0x04,0x04,0x07,0x04,0x04,0x08,0x07,0x00,0x0F,0x00,0x00},
    // 多
    {0x90,0x90,0x48,0x54,0x23,0x92,0x4A,0x66,0x52,0xC0,0x40,0x00,
     0x08,0x08,0x08,0x09,0x05,0x04,0x03,0x02,0x01,0x00,0x00,0x00},
    // 路
    {0x9E,0x12,0xF2,0x9E,0x48,0xC4,0xAB,0x92,0xAA,0xC6,0x40,0x00,
     0x0F,0x08,0x07,0x04,0x00,0x0F,0x04,0x04,0x04,0x0F,0x00,0x00},
    // 源
    {0x11,0x22,0x00,0xFF,0x01,0xF9,0xAD,0xAB,0xA9,0xF9,0x01,0x00,
     0x04,0x02,0x08,0x07,0x04,0x02,0x08,0x0F,0x00,0x02,0x04,0x00},
    // 控
    {0x88,0xFF,0x48,0x00,0x4C,0xA4,0x95,0x86,0x94,0xA4,0x4C,0x00,
     0x08,0x0F,0x00,0x00,0x08,0x08,0x08,0x0F,0x08,0x08,0x08,0x00},
    // 制
    {0x18,0xD6,0x54,0xFF,0x54,0xD4,0x10,0xFC,0x00,0x00,0xFF,0x00,
     0x00,0x07,0x00,0x0F,0x04,0x07,0x00,0x01,0x08,0x08,0x0F,0x00},
    // 系
    {0x00,0x82,0x92,0xDA,0xD6,0xB2,0xB1,0x91,0x89,0xC1,0x80,0x00,
     0x08,0x04,0x02,0x00,0x08,0x0F,0x00,0x00,0x02,0x04,0x09,0x00},
    // 统
    {0x98,0xD4,0xB3,0x88,0x00,0x64,0xD4,0x4D,0xC6,0x54,0xE4,0x00,
     0x04,0x04,0x02,0x02,0x08,0x04,0x03,0x00,0x07,0x08,0x0C,0x00},
    // 地
    {0x10,0x10,0xFF,0x10,0x20,0xFC,0x10,0xFF,0x08,0x84,0xFC,0x00,
     0x04,0x04,0x03,0x02,0x00,0x07,0x08,0x09,0x08,0x08,0x0E,0x00},
    // 址
    {0x10,0x10,0xFF,0x10,0x00,0xF8,0x00,0x00,0xFF,0x10,0x10,0x00,
     0x04,0x04,0x03,0x02,0x08,0x0F,0x08,0x08,0x0F,0x08,0x08,0x00},
    // 维
    {0x98,0xD4,0xB3,0x88,0x10,0xFC,0x27,0x24,0xFD,0x26,0x24,0x00,
     0x04,0x04,0x02,0x02,0x00,0x0F,0x09,0x09,0x0F,0x09,0x09,0x00},
    // 护
    {0x88,0x88,0xFF,0x48,0x00,0xFC,0x44,0x45,0x46,0x44,0xFC,0x00,
     0x00,0x08,0x0F,0x00,0x08,0x07,0x00,0x00,0x00,0x00,0x00,0x00},
    // 是
    {0x40,0x40,0x5F,0x55,0x55,0xD5,0x55,0x55,0x5F,0x40,0x40,0x00,
     0x08,0x04,0x03,0x04,0x08,0x0F,0x09,0x09,0x09,0x09,0x08,0x00},
    // 否
    {0x11,0x91,0x89,0x89,0x85,0xBF,0x81,0x85,0x85,0x89,0x11,0x00,
     0x00,0x0F,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x0F,0x00,0x00},
    // 供
    {0x10,0xFC,0x83,0x88,0xFF,0x88,0x88,0x88,0xFF,0x88,0x80,0x00,
     0x00,0x0F,0x08,0x04,0x02,0x00,0x00,0x00,0x02,0x04,0x08,0x00},
    // 状
    {0x04,0x88,0xFF,0x00,0x10,0x10,0xD0,0x3F,0xD0,0x12,0x14,0x00,
     0x01,0x00,0x0F,0x00,0x08,0x06,0x01,0x00,0x01,0x06,0x08,0x00},
    // 态
    {0x44,0x44,0x24,0x14,0x0C,0xA7,0x4C,0x14,0x24,0x44,0x44,0x00,
     0x04,0x03,0x00,0x07,0x08,0x08,0x0B,0x08,0x0C,0x01,0x06,0x00},
    // 交
    {0x04,0x44,0x24,0x54,0x85,0x06,0x84,0x54,0x24,0x44,0x04,0x00,
     0x08,0x08,0x04,0x04,0x02,0x01,0x02,0x04,0x04,0x08,0x08,0x00},
    // 设
    {0x10,0x11,0xF2,0x00,0x50,0xCF,0x41,0x41,0x4F,0xD0,0x10,0x00,
     0x00,0x00,0x07,0x02,0x08,0x08,0x05,0x02,0x05,0x08,0x08,0x00},
    // 置
    {0x10,0x17,0xD5,0x55,0x57,0x7D,0x57,0x55,0xD5,0x17,0x10,0x00,
     0x08,0x08,0x0F,0x08,0x08,0x0E,0x08,0x08,0x0F,0x08,0x08,0x00},
		// 充
    {0x04,0x44,0x64,0xD4,0x4D,0x46,0x44,0xD4,0x64,0xC4,0x04,0x00,
			0x08,0x08,0x04,0x03,0x00,0x00,0x00,0x07,0x08,0x08,0x0E,0x00},
};
// 新增：32×16图片字模数据（宽32列×高16行，每个图片64字节：上8行32字节+下8行32字节）
static const uint8_t zimo_32x16[][64] = {
/*--  0%  --*/
{0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,
0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0xE0,
0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x07},

/*--  25%  --*/
{0xFC,0x04,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,
0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0xE0,
0x3F,0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x07},

/*--  50%  --*/
{0xFC,0x04,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0x04,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0x04,
0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0xE0,
0x3F,0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x07},

/*--  75%  --*/
{0xFC,0x04,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0x04,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0x04,
0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0xE0,
0x3F,0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,
0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x07},

/*--  100%  --*/
{0xFC,0x04,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0x04,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0x04,
0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0x04,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0x04,0xFC,0xE0,
0x3F,0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,
0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x3F,0x07}
};
// 新增：8×16图片字模数据（宽8列×高16行，每个图片16字节：上8行8字节+下8行8字节）
static const uint8_t tupian_8x16[][16] = {
/*--  8×16图片1  --*/
{0x80,0xC0,0xE0,0xB0,0x98,0x04,0x00,0x00,  // 上8行数据（行0~7，列0~7）
 0x41,0x31,0x19,0x0F,0x07,0x03,0x01,0x00}   // 下8行数据（行8~15，列0~7）
};
// 内部函数：设置地址
static inline void lcd_set_address(uint8_t page, uint8_t col) {
    LCD_LL_WriteCmd(0xB0 + page);                  // 设置页地址
    LCD_LL_WriteCmd(0x00 + (col & 0x0F));          // 列地址低4位
    LCD_LL_WriteCmd(0x10 + ((col >> 4) & 0x0F));   // 列地址高4位
}

// 内部函数：预处理8x16字模
static void get_processed_8x16(Char8x16Index index, uint8_t *out) {
    uint8_t i;
    uint8_t temp[12];
    uint16_t combined;
    
    for (i = 0; i < 6; i++) {
        combined = (zimo_8x16[index][i + 6] << 8) | zimo_8x16[index][i];
        combined <<= 2;
        temp[i] = combined & 0xFF;
        temp[i + 6] = (combined >> 8) & 0xFF;
    }
    
    // 构建16元素数组
    for (i = 0; i <= 5; i++) out[i] = temp[i];
    out[6] = 0x00;
    out[7] = 0x00;
    for (i = 6; i < 12; i++) out[i + 2] = temp[i];
    out[14] = 0x00;
    out[15] = 0x00;
}

// 初始化LCD相关GPIO和LCD控制器
void LCD_LL_Init(void) {
    // 设置初始状态
    LL_GPIO_SetOutputPin(LCD_CS1_PORT, LCD_CS1_PIN);    // 取消片选
    LL_GPIO_SetOutputPin(LCD_RES_PORT, LCD_RES_PIN);    // 不复位
    LL_GPIO_SetOutputPin(LCD_A0_PORT, LCD_A0_PIN);      // A0=1
    LL_GPIO_ResetOutputPin(LCD_SCL_PORT, LCD_SCL_PIN);  // SCL=0
    LL_GPIO_SetOutputPin(LCD_SI_PORT, LCD_SI_PIN);      // SID=1
    LL_GPIO_ResetOutputPin(LCD_BLA_PORT, LCD_BLA_PIN);  // 背光关
    
    // 硬件复位LCD模块
    LL_GPIO_ResetOutputPin(LCD_RES_PORT, LCD_RES_PIN);  // 复位开始
    delay_us(1000);        // 延时
    LL_GPIO_SetOutputPin(LCD_RES_PORT, LCD_RES_PIN);    // 复位结束
    delay_us(10000);       // 等待LCD稳定
    
    // 打开背光
    LL_GPIO_SetOutputPin(LCD_BLA_PORT, LCD_BLA_PIN);    // 打开背光
    
    // 初始化LCD控制器
    LCD_LL_WriteCmd(0xAF);  // 显示开
    LCD_LL_WriteCmd(0x40);  // 显示起始行=0
    LCD_LL_WriteCmd(0xA1);  // ADC=1
    LCD_LL_WriteCmd(0xA6);  // 正常显示
    LCD_LL_WriteCmd(0xA4);  // 显示所有点 = 关
    LCD_LL_WriteCmd(0xA2);  // LCD偏压=1/9
    LCD_LL_WriteCmd(0xC0);  // Common输出模式选择=reverse
    LCD_LL_WriteCmd(0x2F);  // 电源控制 = 全部开启
    LCD_LL_WriteCmd(0x25);  // RA/RB设置
    LCD_LL_WriteCmd(0xF8);  // Booster Ratio设置开始
    LCD_LL_WriteCmd(0x00);  // Booster Ratio=2x,3x,4x
    LCD_LL_WriteCmd(0x81);  // 对比度调整
    LCD_LL_WriteCmd(0x21);  // 对比度值
    
    delay_us(1000);
    LCD_LL_suijiClear();         // 清屏
		delay_us(1000000);
}
//随机清屏函数形成雪花点效果
void LCD_LL_suijiClear(void) {
    uint8_t page, col;
    // 可以添加随机数种子初始化（如果需要每次效果不同）
    // srand((unsigned int)time(NULL));  // 需要包含<time.h>
    
    for(page = 0; page < 8; page++) {
        lcd_set_address(page, 0);
        for(col = 0; col < 128; col++) {
            // 生成0-255之间的随机数并写入，形成雪花点效果
            LCD_LL_WriteData((uint8_t)(rand() % 256));
        }
    }
}
// 清屏函数
void LCD_LL_Clear(void) {
    uint8_t page, col;
    for(page = 0; page < 8; page++) {
        lcd_set_address(page, 0);
        for(col = 0; col < 128; col++) {
            LCD_LL_WriteData(0x00);    // 写入0，清屏
        }
    }
}

// 向LCD写入命令 - 优化时序
void LCD_LL_WriteCmd(uint8_t cmd) {
    uint8_t i;
    
    LL_GPIO_ResetOutputPin(LCD_SCL_PORT, LCD_SCL_PIN);  // SCLK=0
    LL_GPIO_ResetOutputPin(LCD_A0_PORT, LCD_A0_PIN);    // A0=0,表示命令
    LL_GPIO_ResetOutputPin(LCD_CS1_PORT, LCD_CS1_PIN);  // 片选有效
    
    for(i = 0; i < 8; i++) {
        // 输出数据位 (从最高位开始)
        if(cmd & 0x80) {
            LL_GPIO_SetOutputPin(LCD_SI_PORT, LCD_SI_PIN);
        } else {
            LL_GPIO_ResetOutputPin(LCD_SI_PORT, LCD_SI_PIN);
        }
        
        // 精简延时
        for(volatile uint8_t j = 0; j < 2; j++);
        
        // 时钟上升沿，锁存数据
        LL_GPIO_SetOutputPin(LCD_SCL_PORT, LCD_SCL_PIN);
        
        // 精简延时
        for(volatile uint8_t j = 0; j < 2; j++);
        
        // 时钟下降沿
        LL_GPIO_ResetOutputPin(LCD_SCL_PORT, LCD_SCL_PIN);
        
        cmd <<= 1;  // 移到下一位
    }
    
    // 取消片选
    LL_GPIO_SetOutputPin(LCD_CS1_PORT, LCD_CS1_PIN);
    
    // 最小化命令后延时
    for(volatile uint8_t j = 0; j < 5; j++);
}

// 向LCD写入数据 - 优化时序
void LCD_LL_WriteData(uint8_t data) {
    uint8_t i;
    
    LL_GPIO_ResetOutputPin(LCD_SCL_PORT, LCD_SCL_PIN);  // SCLK=0
    LL_GPIO_SetOutputPin(LCD_A0_PORT, LCD_A0_PIN);      // A0=1,表示数据
    LL_GPIO_ResetOutputPin(LCD_CS1_PORT, LCD_CS1_PIN);  // 片选有效
    
    for(i = 0; i < 8; i++) {
        // 输出数据位 (从最高位开始)
        if(data & 0x80) {
            LL_GPIO_SetOutputPin(LCD_SI_PORT, LCD_SI_PIN);
        } else {
            LL_GPIO_ResetOutputPin(LCD_SI_PORT, LCD_SI_PIN);
        }
        
        // 精简延时
        for(volatile uint8_t j = 0; j < 1; j++);
        
        // 时钟上升沿，锁存数据
        LL_GPIO_SetOutputPin(LCD_SCL_PORT, LCD_SCL_PIN);
        
        // 精简延时
        for(volatile uint8_t j = 0; j < 1; j++);
        
        // 时钟下降沿
        LL_GPIO_ResetOutputPin(LCD_SCL_PORT, LCD_SCL_PIN);
        
        data <<= 1;  // 移到下一位
    }
    
    // 取消片选
    LL_GPIO_SetOutputPin(LCD_CS1_PORT, LCD_CS1_PIN);
}

// 显示8×16字符
void LCD_LL_DisplayChar_8x16(uint8_t page, uint8_t col, Char8x16Index index) {
    uint8_t i;
    uint8_t processed_zimo[16];
    
    get_processed_8x16(index, processed_zimo);
    
    // 显示上8行
    lcd_set_address(page, col);
    for(i = 0; i < 8; i++) {
        LCD_LL_WriteData(processed_zimo[i]);
    }
    
    // 显示下8行
    lcd_set_address(page + 1, col);
    for(i = 8; i < 16; i++) {
        LCD_LL_WriteData(processed_zimo[i]);
    }
}

// 显示16×16汉字（优化版）
void LCD_LL_DisplayChar_16x16(uint8_t page, uint8_t col, Char16x16Index index) {
    uint8_t i;
    uint8_t processed_zimo[24];
    uint16_t combined;
    uint8_t right_col = (col + 6) % 128;
    
    // 字模预处理
    for (i = 0; i < 12; i++) {
        combined = (zimo_12x16[index - INDEX_HAN_BEN][i + 12] << 8) | zimo_12x16[index - INDEX_HAN_BEN][i];
        combined <<= 2;
        processed_zimo[i] = combined & 0xFF;
        processed_zimo[i + 12] = (combined >> 8) & 0xFF;
    }
    
    // 合并上8行数据传输
    LCD_LL_WriteCmd(0xB0 + page);
    // 左半6列
    lcd_set_address(page, col);
    for(i = 0; i < 6; i++) {
        LCD_LL_WriteData(processed_zimo[i]);
    }
    // 右半6列
    lcd_set_address(page, right_col);
    for(i = 6; i < 12; i++) {
        LCD_LL_WriteData(processed_zimo[i]);
    }
    
    // 合并下8行数据传输
    LCD_LL_WriteCmd(0xB0 + page + 1);
    // 左半6列
    lcd_set_address(page + 1, col);
    for(i = 12; i < 18; i++) {
        LCD_LL_WriteData(processed_zimo[i]);
    }
    // 右半6列
    lcd_set_address(page + 1, right_col);
    for(i = 18; i < 24; i++) {
        LCD_LL_WriteData(processed_zimo[i]);
    }
}
// 新增：显示32×16图片（起始页、起始列、图片索引）
// 说明：page为上8行起始页，下8行自动占用page+1；col为起始列，占用32列（col~col+31）
void LCD_LL_DisplayPic_32x16(uint8_t page, uint8_t col, Pic32x16Index index) {
    uint8_t i;
    const uint8_t *pic_zimo;

    // 边界检查：索引超出范围或起始列+32超出LCD宽度（128列）则退出
    if (index >= PIC_MAX || (col + 31) >= 128) {
        return;
    }

    // 获取目标图片的字模数据（上8行：index[0~31]，下8行：index[32~63]）
    pic_zimo = zimo_32x16[index];

    // 1. 显示上8行（占用page页，col~col+31列）
    lcd_set_address(page, col);  // 设置上8行起始地址
    for (i = 0; i < 32; i++) {
        LCD_LL_WriteData(pic_zimo[i]);  // 连续写入32列数据
    }

    // 2. 显示下8行（占用page+1页，col~col+31列）
    lcd_set_address(page + 1, col);  // 设置下8行起始地址
    for (i = 32; i < 64; i++) {
        LCD_LL_WriteData(pic_zimo[i]);  // 连续写入32列数据
    }
}

// 新增：显示8×16图片（起始页、起始列、图片索引）
// 说明：page为上8行起始页，下8行自动占用page+1；col为起始列，占用8列（col~col+7）
void LCD_LL_DisplayPic_8x16(uint8_t page, uint8_t col, Pic8x16Index index) {
    uint8_t i;
    const uint8_t *pic_zimo;

    // 边界检查：1.索引超出范围 2.起始列+7超出LCD宽度（128列） 3.下8行页面超出范围（LCD共8页：0~7）
    if (index >= PIC_MAX1 || (col + 7) >= 128 || (page + 1) >= 8) {
        return;
    }

    // 获取目标图片的字模数据（上8行：index[0~7]，下8行：index[8~15]）
    pic_zimo = tupian_8x16[index];

    // 1. 显示上8行（占用page页，col~col+7列）
    lcd_set_address(page, col);  // 设置上8行起始地址（page页，col列）
    for (i = 0; i < 8; i++) {
        LCD_LL_WriteData(pic_zimo[i]);  // 连续写入上8行的8列数据
    }

    // 2. 显示下8行（占用page+1页，col~col+7列）
    lcd_set_address(page + 1, col);  // 设置下8行起始地址（page+1页，col列）
    for (i = 8; i < 16; i++) {
        LCD_LL_WriteData(pic_zimo[i]);  // 连续写入下8行的8列数据
    }
}

// 显示数字（支持小数）- 批量传输优化
void LCD_LL_DisplayNumber_8x16(uint8_t page, uint8_t col, float number, uint8_t intDigits, uint8_t decDigits) {
    int32_t integerPart, decimalPart;
    uint8_t i, digit;
    bool negative = false;
    uint8_t currentCol = col;
    uint8_t processed_zimo[16];
    
    if(number < 0) {
        negative = true;
        number = -number;
    }
    
    integerPart = (int32_t)number;
    decimalPart = 0;
    
    if(decDigits > 0) {
        float decFactor = 1.0f;
        for(i = 0; i < decDigits; i++) decFactor *= 10.0f;
        decimalPart = (int32_t)((number - integerPart) * decFactor + 0.5f);
    }
    
    // 批量处理上8行
    LCD_LL_WriteCmd(0xB0 + page);
    if(negative) {
        get_processed_8x16(INDEX_HENG, processed_zimo);
        lcd_set_address(page, currentCol);
        for(i = 0; i < 8; i++) {
            LCD_LL_WriteData(processed_zimo[i]);
        }
        currentCol += 8;
    }
    
    for(i = intDigits; i > 0; i--) {
        int32_t divisor = 1;
        for(uint8_t j = 1; j < i; j++) divisor *= 10;
        digit = (integerPart / divisor) % 10;
        
        get_processed_8x16(digit, processed_zimo);
        lcd_set_address(page, currentCol);
        for(uint8_t k = 0; k < 8; k++) {
            LCD_LL_WriteData(processed_zimo[k]);
        }
        currentCol += 8;
    }
    
    if(decDigits > 0) {
        get_processed_8x16(INDEX_DIAN, processed_zimo);
        lcd_set_address(page, currentCol);
        for(i = 0; i < 8; i++) {
            LCD_LL_WriteData(processed_zimo[i]);
        }
        currentCol += 8;
    }
    
    for(i = decDigits; i > 0; i--) {
        int32_t divisor = 1;
        for(uint8_t j = 1; j < i; j++) divisor *= 10;
        digit = (decimalPart / divisor) % 10;
        
        get_processed_8x16(digit, processed_zimo);
        lcd_set_address(page, currentCol);
        for(uint8_t k = 0; k < 8; k++) {
            LCD_LL_WriteData(processed_zimo[k]);
        }
        currentCol += 8;
    }
    
    // 批量处理下8行
    currentCol = col;
    LCD_LL_WriteCmd(0xB0 + page + 1);
    if(negative) {
        get_processed_8x16(INDEX_HENG, processed_zimo);
        lcd_set_address(page + 1, currentCol);
        for(i = 8; i < 16; i++) {
            LCD_LL_WriteData(processed_zimo[i]);
        }
        currentCol += 8;
    }
    
    for(i = intDigits; i > 0; i--) {
        int32_t divisor = 1;
        for(uint8_t j = 1; j < i; j++) divisor *= 10;
        digit = (integerPart / divisor) % 10;
        
        get_processed_8x16(digit, processed_zimo);
        lcd_set_address(page + 1, currentCol);
        for(uint8_t k = 8; k < 16; k++) {
            LCD_LL_WriteData(processed_zimo[k]);
        }
        currentCol += 8;
    }
    
    if(decDigits > 0) {
        get_processed_8x16(INDEX_DIAN, processed_zimo);
        lcd_set_address(page + 1, currentCol);
        for(i = 8; i < 16; i++) {
            LCD_LL_WriteData(processed_zimo[i]);
        }
        currentCol += 8;
    }
    
    for(i = decDigits; i > 0; i--) {
        int32_t divisor = 1;
        for(uint8_t j = 1; j < i; j++) divisor *= 10;
        digit = (decimalPart / divisor) % 10;
        
        get_processed_8x16(digit, processed_zimo);
        lcd_set_address(page + 1, currentCol);
        for(uint8_t k = 8; k < 16; k++) {
            LCD_LL_WriteData(processed_zimo[k]);
        }
        currentCol += 8;
    }
}

// 显示8x16字符串 - 批量传输优化
void LCD_LL_DisplayString_8x16(uint8_t page, uint8_t start_col, const char *str) {
    if (!str) return;

    uint8_t current_col = start_col;
    uint8_t char_index;
    uint8_t processed_zimo[16];
    uint8_t str_len = strlen(str);
    
    // 批量处理上8行
    LCD_LL_WriteCmd(0xB0 + page);
    for (uint8_t s = 0; s < str_len; s++) {
        // 获取字符索引
        switch(str[s]) {
            case '0': char_index = INDEX_NUM0; break;
            case '1': char_index = INDEX_NUM1; break;
            case '2': char_index = INDEX_NUM2; break;
            case '3': char_index = INDEX_NUM3; break;
            case '4': char_index = INDEX_NUM4; break;
            case '5': char_index = INDEX_NUM5; break;
            case '6': char_index = INDEX_NUM6; break;
            case '7': char_index = INDEX_NUM7; break;
            case '8': char_index = INDEX_NUM8; break;
            case '9': char_index = INDEX_NUM9; break;
            case ':': char_index = INDEX_MAO; break;
            case '.': char_index = INDEX_DIAN; break;
            case 'V': char_index = INDEX_V; break;
            case 'A': char_index = INDEX_A; break;
            case 'm': char_index = INDEX_m; break;
            case '-': char_index = INDEX_HENG; break;
            case 'S': char_index = INDEX_S; break;
            default: continue;
        }

        get_processed_8x16(char_index, processed_zimo);
        lcd_set_address(page, current_col);
        for(uint8_t i = 0; i < 8; i++) {
            LCD_LL_WriteData(processed_zimo[i]);
        }
        
        current_col += 8;
    }
    
    // 批量处理下8行
    current_col = start_col;
    LCD_LL_WriteCmd(0xB0 + page + 1);
    for (uint8_t s = 0; s < str_len; s++) {
        // 获取字符索引
        switch(str[s]) {
            case '0': char_index = INDEX_NUM0; break;
            case '1': char_index = INDEX_NUM1; break;
            case '2': char_index = INDEX_NUM2; break;
            case '3': char_index = INDEX_NUM3; break;
            case '4': char_index = INDEX_NUM4; break;
            case '5': char_index = INDEX_NUM5; break;
            case '6': char_index = INDEX_NUM6; break;
            case '7': char_index = INDEX_NUM7; break;
            case '8': char_index = INDEX_NUM8; break;
            case '9': char_index = INDEX_NUM9; break;
            case ':': char_index = INDEX_MAO; break;
            case '.': char_index = INDEX_DIAN; break;
            case 'V': char_index = INDEX_V; break;
            case 'A': char_index = INDEX_A; break;
            case 'm': char_index = INDEX_m; break;
            case '-': char_index = INDEX_HENG; break;
            case 'S': char_index = INDEX_S; break;
            default: continue;
        }

        get_processed_8x16(char_index, processed_zimo);
        lcd_set_address(page + 1, current_col);
        for(uint8_t i = 8; i < 16; i++) {
            LCD_LL_WriteData(processed_zimo[i]);
        }
        
        current_col += 8;
    }
}

// 显示欢迎页面
static void LCD_LL_ShowWelcomePage(LcdGlobalData *data) {
    // 多路电源
    LCD_LL_DisplayChar_16x16(2, 40+4, INDEX_HAN_DUO);        	 // 多
    LCD_LL_DisplayChar_16x16(2, 52+4, INDEX_HAN_LU);      	   // 路
    LCD_LL_DisplayChar_16x16(2, 64+4, INDEX_HAN_DIAN);   	     // 电
    LCD_LL_DisplayChar_16x16(2, 76+4, INDEX_HAN_YUAN);         // 源
    
	  // 控制系统...
    LCD_LL_DisplayChar_16x16(4, 32+4, INDEX_HAN_KONG);        // 控
    LCD_LL_DisplayChar_16x16(4, 44+4, INDEX_HAN_ZHI);      	  // 制
    LCD_LL_DisplayChar_16x16(4, 56+4, INDEX_HAN_XI);   	      // 系
    LCD_LL_DisplayChar_16x16(4, 68+4, INDEX_HAN_TONG2);       // 统
	  LCD_LL_DisplayChar_8x16(4, 80+4, INDEX_DIAN);             // .
 	  LCD_LL_DisplayChar_8x16(4, 88+4, INDEX_DIAN);             // .
    LCD_LL_DisplayChar_8x16(4, 96+4, INDEX_DIAN);             // .
}

// 显示设置界面
static void LCD_LL_ShowSettingPage(LcdGlobalData *data) {
     // 标题：设置
    LCD_LL_DisplayChar_16x16(2, 4, INDEX_HAN_SHE);      // 设
    LCD_LL_DisplayChar_16x16(2, 16, INDEX_HAN_ZHI3);      // 置
    
    // 地址设置
    LCD_LL_DisplayChar_16x16(2, 28, INDEX_HAN_DI);     // 地
    LCD_LL_DisplayChar_16x16(2, 40, INDEX_HAN_ZHI2);      // 址
    LCD_LL_DisplayChar_8x16(2, 52, INDEX_MAO);           // ：
	if(data->yk_modbusAddress < 100){
    LCD_LL_DisplayNumber_8x16(2, 70, data->yk_modbusAddress, 2, 0);
	}else{LCD_LL_DisplayNumber_8x16(2, 70, data->yk_modbusAddress, 3, 0);}
}

// 显示第一页
static void LCD_LL_ShowPage1(LcdGlobalData *data) {
    // Modbus地址
    LCD_LL_DisplayChar_16x16(0, 0+4, INDEX_HAN_DIAN);     // 地
    LCD_LL_DisplayChar_16x16(0, 12+4, INDEX_HAN_ZHI2);      // 址
    LCD_LL_DisplayChar_8x16(0, 24+4, INDEX_MAO);           // ：
	if(data->modbusAddress < 100){
    LCD_LL_DisplayNumber_8x16(0, 32+4, data->modbusAddress, 2, 0);
	}else{LCD_LL_DisplayNumber_8x16(0, 32+4, data->modbusAddress, 3, 0);}
   
    // 电池电压
    LCD_LL_DisplayChar_16x16(2, 0+4, INDEX_HAN_DIAN);      // 电
    LCD_LL_DisplayChar_16x16(2, 12+4, INDEX_HAN_CHI);      // 池
    LCD_LL_DisplayChar_16x16(2, 24+4, INDEX_HAN_DIAN);     // 电
    LCD_LL_DisplayChar_16x16(2, 36+4, INDEX_HAN_YA);       // 压
    LCD_LL_DisplayChar_8x16(2, 48+4, INDEX_MAO);           // ：
    LCD_LL_DisplayNumber_8x16(2, 70+4, data->batteryVoltage, 2, 1);
    LCD_LL_DisplayChar_8x16(2, 102+4, INDEX_V);            // V
    
    // 维护放电
    LCD_LL_DisplayChar_16x16(4, 0+4, INDEX_HAN_WEI);         // 维
    LCD_LL_DisplayChar_16x16(4, 12+4, INDEX_HAN_HU);         // 护
    LCD_LL_DisplayChar_16x16(4, 24+4, INDEX_HAN_FANG);       // 放
    LCD_LL_DisplayChar_16x16(4, 36+4, INDEX_HAN_DIAN);    	 // 电
    LCD_LL_DisplayChar_8x16(4, 48+4, INDEX_MAO);          	 // ：
	if(data->isMaintenanceDischarge){
    LCD_LL_DisplayChar_16x16(4, 70+4, INDEX_HAN_SHI);    			 // 是
	}else{LCD_LL_DisplayChar_16x16(4, 70+4, INDEX_HAN_FOU);    	 // 否}
}
	  // 供电状态
    LCD_LL_DisplayChar_16x16(6, 0+4, INDEX_HAN_GONG);        	 // 供
    LCD_LL_DisplayChar_16x16(6, 12+4, INDEX_HAN_DIAN);      	 // 电
    LCD_LL_DisplayChar_16x16(6, 24+4, INDEX_HAN_ZHUANG);   	   // 状
    LCD_LL_DisplayChar_16x16(6, 36+4, INDEX_HAN_TAI);          // 态
    LCD_LL_DisplayChar_8x16(6, 48+4, INDEX_MAO);               // ：
	if(data->powerSupplyStatus){
    LCD_LL_DisplayChar_16x16(6, 70+4, INDEX_HAN_JIAO);         // 交
		LCD_LL_DisplayChar_16x16(6, 82+4, INDEX_HAN_LIU);          // 流
	}else{LCD_LL_DisplayChar_16x16(6+4, 70, INDEX_HAN_DIAN);     // 电
		LCD_LL_DisplayChar_16x16(6, 82+4, INDEX_HAN_CHI);          // 池
		}

	}

// 显示第二页
static void LCD_LL_ShowPage2(LcdGlobalData *data) {
    // 放(充)电电流
	if(data->powerSupplyStatus){LCD_LL_DisplayChar_16x16(0, 0+4, INDEX_HAN_CHONG);  //充
		
	}else
    {LCD_LL_DisplayChar_16x16(0, 0+4, INDEX_HAN_FANG);}      // 放
    LCD_LL_DisplayChar_16x16(0, 12+4, INDEX_HAN_DIAN);     // 电
    LCD_LL_DisplayChar_16x16(0, 24+4, INDEX_HAN_DIAN);     // 电
    LCD_LL_DisplayChar_16x16(0, 36+4, INDEX_HAN_LIU);      // 流
    LCD_LL_DisplayChar_8x16(0, 48+4, INDEX_MAO);           // ：
    if(data->dischargeCurrent >= 1000){
    LCD_LL_DisplayNumber_8x16(0, 80, data->dischargeCurrent, 4, 0);  // 电流值		// ：
		}else{
			    if(data->dischargeCurrent >= 100){LCD_LL_DisplayNumber_8x16(0, 88, data->dischargeCurrent, 3, 0);  // 电流值		// ：
					}else{if(data->safetyCurrent >= 10){
					LCD_LL_DisplayNumber_8x16(0, 96, data->dischargeCurrent, 2, 0);
					}else{
					LCD_LL_DisplayNumber_8x16(0, 104, data->dischargeCurrent, 1, 0);
					}}
      		} 
		 
    LCD_LL_DisplayChar_8x16(0, 112, INDEX_m);                // m
    LCD_LL_DisplayChar_8x16(0, 120, INDEX_A);                // A
    
    // 电池容量
    LCD_LL_DisplayChar_16x16(2, 0+4, INDEX_HAN_DIAN);        // 电
    LCD_LL_DisplayChar_16x16(2, 12+4, INDEX_HAN_CHI);        // 池
    LCD_LL_DisplayChar_16x16(2, 24+4, INDEX_HAN_RONG);       // 容
    LCD_LL_DisplayChar_16x16(2, 36+4, INDEX_HAN_LIANG);      // 量
    LCD_LL_DisplayChar_8x16(2, 48+4, INDEX_MAO);             // ：
		if(data->batteryCapacity >= 80){
    LCD_LL_DisplayPic_32x16(2, 65+4, PIC_100_PERCENT);}
		if((data->batteryCapacity >= 60)&(data->batteryCapacity < 80)){
    LCD_LL_DisplayPic_32x16(2, 65+4, PIC_75_PERCENT);}
		if((data->batteryCapacity >= 40)&(data->batteryCapacity < 60)){
    LCD_LL_DisplayPic_32x16(2, 65+4, PIC_50_PERCENT);}
	  if((data->batteryCapacity >= 20)&(data->batteryCapacity < 40)){
    LCD_LL_DisplayPic_32x16(2, 65+4, PIC_25_PERCENT);}
		if(data->batteryCapacity < 20){
    LCD_LL_DisplayPic_32x16(2, 65+4, PIC_0_PERCENT);}
	 
		if(data->powerSupplyStatus){
		LCD_LL_DisplayPic_8x16(2, 98+4, PIC_0);}
    // 版本
    LCD_LL_DisplayChar_16x16(4, 0+4, INDEX_HAN_BAN);       // 版
    LCD_LL_DisplayChar_16x16(4, 12+4, INDEX_HAN_BEN);       // 本
    LCD_LL_DisplayChar_8x16(4, 24+4, INDEX_MAO);           // ：
    LCD_LL_DisplayNumber_8x16(4, 32+4, data->versionMajor, 1, 0);
    LCD_LL_DisplayChar_8x16(4, 40+4, INDEX_DIAN);          // .
    LCD_LL_DisplayNumber_8x16(4, 48+4, data->versionMinor, 2, 0);
		// 通信 周期
    LCD_LL_DisplayChar_16x16(6, 0+4, INDEX_HAN_TONG);               // 通
    LCD_LL_DisplayChar_16x16(6, 12+4, INDEX_HAN_XIN);              // 信
    LCD_LL_DisplayChar_8x16(6, 24+4, INDEX_MAO);                   // ：
    if(data->communicationStatus){
		LCD_LL_DisplayChar_16x16(6, 32+4, INDEX_HAN_TONG);             // 通
		}else{LCD_LL_DisplayChar_16x16(6, 32+4, INDEX_HAN_DUAN);       // 断
			}
		LCD_LL_DisplayChar_16x16(6, 68+4, INDEX_HAN_ZHOU);               // 周
    LCD_LL_DisplayChar_16x16(6, 80+4, INDEX_HAN_QI);              // 期
    LCD_LL_DisplayChar_8x16(6, 92+4, INDEX_MAO);                   // ：
		LCD_LL_DisplayChar_8x16(6, 100+4, INDEX_HENG);                   // -	
		LCD_LL_DisplayChar_8x16(6, 108+4, INDEX_HENG);                   // -	
}

// 显示第三页
static void LCD_LL_ShowPage3(LcdGlobalData *data) {
   LCD_LL_Clear();
    
    // 本安输出电压
    LCD_LL_DisplayChar_16x16(0, 0+4, INDEX_HAN_BEN);       // 本
    LCD_LL_DisplayChar_16x16(0, 12+4, INDEX_HAN_AN);       // 安
    LCD_LL_DisplayChar_16x16(0, 24+4, INDEX_HAN_SHU);      // 输
    LCD_LL_DisplayChar_16x16(0, 36+4, INDEX_HAN_CHU);      // 出
    LCD_LL_DisplayChar_16x16(0, 48+4, INDEX_HAN_DIAN);     // 电
    LCD_LL_DisplayChar_16x16(0, 60+4, INDEX_HAN_YA);       // 压
    LCD_LL_DisplayChar_8x16(0, 72+4, INDEX_MAO);           // ：
    LCD_LL_DisplayNumber_8x16(0, 88, data->safetyVoltage, 2, 1);
    LCD_LL_DisplayChar_8x16(0, 120, INDEX_V);            // V
    
    // 本安输出电流
    LCD_LL_DisplayChar_16x16(2, 0+4, INDEX_HAN_BEN);       // 本
    LCD_LL_DisplayChar_16x16(2, 12+4, INDEX_HAN_AN);       // 安
    LCD_LL_DisplayChar_16x16(2, 24+4, INDEX_HAN_SHU);      // 输
    LCD_LL_DisplayChar_16x16(2, 36+4, INDEX_HAN_CHU);      // 出
    LCD_LL_DisplayChar_16x16(2, 48+4, INDEX_HAN_DIAN);     // 电
    LCD_LL_DisplayChar_16x16(2, 60+4, INDEX_HAN_LIU);      // 流
    LCD_LL_DisplayChar_8x16(2, 72+4, INDEX_MAO);            // ：
		if(data->safetyCurrent >= 1000){
    LCD_LL_DisplayNumber_8x16(2, 80, data->safetyCurrent, 4, 0);  // 电流值		// ：
		}else{
			    if(data->safetyCurrent >= 100){LCD_LL_DisplayNumber_8x16(2, 88, data->safetyCurrent, 3, 0);  // 电流值		// ：
					}else{if(data->safetyCurrent >= 10){
					LCD_LL_DisplayNumber_8x16(2, 96, data->safetyCurrent, 2, 0);
					}else{
					LCD_LL_DisplayNumber_8x16(2, 104, data->safetyCurrent, 1, 0);
					}}
      		} 
    LCD_LL_DisplayChar_8x16(2, 112, INDEX_m);                // m
    LCD_LL_DisplayChar_8x16(2, 120, INDEX_A);                // A
}

// 显示指定页面
void LCD_LL_ShowPage(PageIndex page, LcdGlobalData *data) {
    if(data == NULL) return;
    
    LCD_LL_Clear();  // 清屏
    
    switch(page) {
        case PAGE_WELCOME:
            LCD_LL_ShowWelcomePage(data);
            break;
        case PAGE_1:
            LCD_LL_ShowPage1(data);
            break;
        case PAGE_2:
            LCD_LL_ShowPage2(data);
            break;
        case PAGE_3:
            LCD_LL_ShowPage3(data);
            break;
        case PAGE_SETTING:
            LCD_LL_ShowSettingPage(data);
            break;
        default:
            break;
    }
}

// LCD测试函数
void LCD_LL_TestDisplay(LcdGlobalData *data) {
    LCD_LL_Clear();
    
    // 本安输出电压
    LCD_LL_DisplayChar_16x16(0, 0, INDEX_HAN_BEN);       // 本
    LCD_LL_DisplayChar_16x16(0, 12, INDEX_HAN_AN);       // 安
    LCD_LL_DisplayChar_16x16(0, 24, INDEX_HAN_SHU);      // 输
    LCD_LL_DisplayChar_16x16(0, 36, INDEX_HAN_CHU);      // 出
    LCD_LL_DisplayChar_16x16(0, 48, INDEX_HAN_DIAN);     // 电
    LCD_LL_DisplayChar_16x16(0, 60, INDEX_HAN_YA);       // 压
    LCD_LL_DisplayChar_8x16(0, 72, INDEX_MAO);           // ：
    LCD_LL_DisplayNumber_8x16(0, 88, data->safetyVoltage, 2, 1);
    LCD_LL_DisplayChar_8x16(0, 120, INDEX_V);            // V
    
    // 本安输出电流
    LCD_LL_DisplayChar_16x16(2, 0, INDEX_HAN_BEN);       // 本
    LCD_LL_DisplayChar_16x16(2, 12, INDEX_HAN_AN);       // 安
    LCD_LL_DisplayChar_16x16(2, 24, INDEX_HAN_SHU);      // 输
    LCD_LL_DisplayChar_16x16(2, 36, INDEX_HAN_CHU);      // 出
    LCD_LL_DisplayChar_16x16(2, 48, INDEX_HAN_DIAN);     // 电
    LCD_LL_DisplayChar_16x16(2, 60, INDEX_HAN_LIU);      // 流
    LCD_LL_DisplayChar_8x16(2, 72, INDEX_MAO);            // ：
		if(data->safetyCurrent >= 1000){
    LCD_LL_DisplayNumber_8x16(2, 80, data->safetyCurrent, 4, 0);  // 电流值		// ：
		}else{
			    if(data->safetyCurrent >= 100){LCD_LL_DisplayNumber_8x16(2, 88, data->safetyCurrent, 3, 0);  // 电流值		// ：
					}else{if(data->safetyCurrent >= 10){
					LCD_LL_DisplayNumber_8x16(2, 96, data->safetyCurrent, 2, 0);
					}else{
					LCD_LL_DisplayNumber_8x16(2, 104, data->safetyCurrent, 1, 0);
					}}
      		} 
    LCD_LL_DisplayChar_8x16(2, 112, INDEX_m);                // m
    LCD_LL_DisplayChar_8x16(2, 120, INDEX_A);                // A
}
